/**
 * 向服务器发送用户的注册参数,在前端做必要的类型和格式的检查
 * 通过后端返回的数据code(200/400),是向用户显示注册成功并跳转还是显示错误原因
 * @constructor
 */
function VerifyRegister() {
    var name = $("#name").val().trim()
    var phone = $("#phone").val().trim()
    var idCard = $("#idCard").val().trim()
    var email_prefix = $("#email_prefix").val().trim()
    var email_suffix = $("#email_suffix").val().trim()
    var password = $("#password").val().trim()
    var flag = true

    if (name === "" || phone === "" || idCard === "" || password === "") {
        flag = false
        alert("输入格式不正确")
    }else if (phone.length !== 11) {
        flag = false
        alert("电话号码需要为11位")
    }else if (idCard.length !== 18) {
        flag = false
        alert("身份证号需要为18位")
    }else if (email_prefix.length === 0 && email_suffix.length !== 0) {
        flag = false
        alert("邮箱输入格式有误")
    }else if (email_prefix.length !== 0 && email_suffix.length === 0) {
        flag = false
        alert("邮箱输入格式有误")
    }

    if (flag) {
        var data = {
            name: name,
            phone: phone,
            idCard: idCard,
            email: email_prefix + "@" + email_suffix,
            password: md5(password)
        }
        $.ajax({
            async:true,
            url:"/verifyRegister",
            data:JSON.stringify(data),
            contentType: "application/json;charset=utf-8",
            dataType:"json",
            type:"post",
            success:function(response) {
                if (response['code'] === "200") {
                    window.location.href="/user?uId="+response['uId']
                }else {
                    alert(response['msg'])
                }
            },
            error:function(){
                alert("服务器请求出现错误")
            }
        })
    }

}





